var windowName = "myService";
var Page,servList;
apiready = function(){
    servList = new List()
    onWindowShow(function () {
        console.log(windowName + " show")
    })
    onWindowHide(function () {
        console.log(windowName + " hide")
    })
    console.log("index page is OK");
    Page = createVM("#Page",{
        curTab:0
        ,list:[]
        ,saleList:[]
        ,auditList:[]
        ,storeList:[]
    },{
        //页面方法
        "init":function () {
            var _this = this
            showLoading();
            servList.setUrl("/api/products").setCbFunc(function (res) {
                clearLoading();
                logJson(res)
                Page.list = res;
                var saleList = [];
                var auditList = [];
                var storeList = [];
                res.map(function (data) {
                    switch (data.status) {
                        case 0:
                            auditList.push(data);
                            break;
                        case 100:
                            auditList.push(data);
                            break;
                        case 200:
                            saleList.push(data);
                            break;
                        case 250:
                            storeList.push(data);
                            break;
                    }
                })
                Page.auditList = auditList;
                Page.saleList = saleList;
                Page.storeList = storeList;

            }).getList()
        }
        // ,OnPullUpLoadMore:function () {
        //     startPullUpLoadMore();
        //     servList.getList()
        // },
        // OnPullDownRefresh:function () {
        //     startPullDownRefresh();
        //     servList.reload();
        // }
        ,tab:function (index) {
            log(index)
        }
        ,del:function (id) {
            showLoading();
            apiPost("/api/products/delete",{id:id,status:200},function (res,code) {
                if (code == 200) {
                    servList.reload();
                }
            })
        }
        ,toStore:function (id) {
            showLoading();
            apiPost("/api/products",{id:id,status:250},function (res,code) {
                logJson(res)
                if (code == 200) {
                    servList.reload();
                }
            })
        }
        ,onSale:function (id) {
            showLoading();
            apiPost("/api/products",{id:id,status:200},function (res,code) {
                logJson(res)
                if (code == 200) {
                    servList.reload();
                }
            })
        }
    })
    Page.init()
}